<?php

include_once('Classes/Connect.php');
include('Classes/Utils.php');

define('FAST_SERVICE_ROOT', dirname(__FILE__));

global $dbSingleton;
// TODO : store this and return results if request are made form less than xx seconds

$queryResult = $dbSingleton->query('SELECT id, object_id, nom, prenom FROM msa_clientobject');
$res = 'var c_ = new Array(); ';
$res .= 'var cli = new Array(); ';
if (is_object($queryResult)) {
    $queryResult->setFetchMode(PDO::FETCH_OBJ);
    $c = 0;
    while ($user = $queryResult->fetch()) {
        //$res.= 'cli.push({"value":"' . (int) ($user->id) . '", "label":"' . $user->nom . ' ' . $user->prenom . '"});';
        $res .= 'c_.push({"value":'.(int) ($user->id).', "label":"'.$user->nom . ' ' . $user->prenom.'"});';
        //$res.= 'c_["'.(int) ($user->id).'"] = "'.$user->nom . ' ' . $user->prenom.'";'; //cli.push({"value":"' . (int) ($user->id) . '", "label":"' . $user->nom . ' ' . $user->prenom . '"});';
        $c++;
    }
    // Save bytes
    /*$res .= 'for(var key in c_) {';
    $res .= '   name = c_[key];';
    $res .= '   c_.push({"value":key, "label":name});';
    $res .= '}';*/
    
} 
echo $res . ';';